// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "HookEngine.h"
#include "ExceptionList.h"
#include "HookSettingReader.h"

auto_ptr<HookSettingReader> g_pHookSettingReader;

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch(ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		TRACE(TEXT("[Debug]--DllMain(DLL_PROCESS_ATTACH)\n"));


		try
		{
			g_pHookSettingReader.reset( new HookSettingReader(L"D:\\HookSetting.hook") );
			assert( g_pHookSettingReader.get() !=NULL );
		}
		catch(ArgumentException&)
		{
			return FALSE;
		}

		if(!g_pHookSettingReader->StartHook())
			return FALSE;
		break;

	case DLL_THREAD_DETACH:
		TRACE(TEXT("[Debug]--DllMain(DLL_THREAD_DETACH)\n"));
		FreeTLSMemory();
		break;

	case DLL_PROCESS_DETACH:
		TRACE(TEXT("[Debug]--DllMain(DLL_PROCESS_DETACH)\n"));
		assert( g_pHookSettingReader.get()!=NULL );
		g_pHookSettingReader->StopHook();
		break;
	}
    return TRUE;
}
